package addressBook;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class searchWindowView extends JFrame {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public contacts myContacts;
	
	private JLabel label1 = new JLabel("first name:");
	private JTextField textField1 = new JTextField(10);
	private JLabel label2 = new JLabel("last name:");
	private JTextField textField2 = new JTextField(10);
	private JLabel label3 = new JLabel("phone number:");
	private JTextField textField3 = new JTextField(10);
	private JLabel label4 = new JLabel("street address:");
	private JTextField textField4 = new JTextField(10);
	private JLabel label5 = new JLabel("city:");
	private JTextField textField5 = new JTextField(10);
	private JLabel label6 = new JLabel("url:");
	private JTextField textField6 = new JTextField(10);
	private JLabel label7 = new JLabel("email:");
	private JTextField textField7 = new JTextField(10);
	private JButton button = new JButton("Search");

	public searchWindowView(contacts toContacts) {
		
		myContacts = toContacts;
		
		JPanel panel = new JPanel(new SpringLayout());
		JPanel buttonPanel = new JPanel();
		JPanel totalPanel = new JPanel(new BorderLayout());
		
    	this.setTitle("Search Contact");
        this.setSize(new Dimension(300, 400));
        this.setDefaultCloseOperation(HIDE_ON_CLOSE);
        this.setLocationRelativeTo(null);
        this.setResizable(false);
 
		panel.add(label1);
		label1.setLabelFor(textField1);
		panel.add(textField1);
		panel.add(label2);
		label2.setLabelFor(textField2);
		panel.add(textField2);
		panel.add(label3);
		label3.setLabelFor(textField3);
		panel.add(textField3);
		panel.add(label4);
		label4.setLabelFor(textField4);
		panel.add(textField4);
		panel.add(label5);
		label5.setLabelFor(textField5);
		panel.add(textField5);
		panel.add(label6);
		label6.setLabelFor(textField6);
		panel.add(textField6);
		panel.add(label7);
		label7.setLabelFor(textField7);
		panel.add(textField7);
		
        SpringUtilities.makeCompactGrid(panel, 7, 2, 6, 6, 6, 6);
		
		buttonPanel.add(button);
		
		panel.setOpaque(true);
		
		totalPanel.add(buttonPanel, BorderLayout.SOUTH);
		totalPanel.add(panel, BorderLayout.NORTH);
		
		this.setContentPane(totalPanel);
        
    }
    
    public String getFirstName(){
    	
    	return textField1.getText();
    
    }
    
    public String getLastName(){
    	
    	return textField2.getText();
    
    }
    
    public String getPhoneNumber(){
    	
    	return textField3.getText();
    
    }
    
    public String getAddress(){
    	
    	return textField4.getText();
    
    }
    
    public String getCity(){
    	
    	return textField5.getText();
    
    }
    
    public String getUrl(){
    	return textField6.getText();
    }
    
    public String getEmail(){
    	return textField7.getText();
    }

    void addButtonListener(ActionListener listenForEnterButton){
		
		button.addActionListener(listenForEnterButton);
		
	}
    
	void displayErrorMessage(IllegalArgumentException ex){
		
		JOptionPane.showMessageDialog(this, ex.getMessage());
		
	}
	
}
